package gen.tools.svn;

import gen.tools.Widgets;
import gen.tools.structures.L1S1;

import java.io.IOException;
import java.util.ArrayList;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.google.gson.Gson;

public class ChkFileRevision extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    public ChkFileRevision() {
        super();
    }

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request,response);
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		final Widgets wid = new Widgets();
		request.setCharacterEncoding( wid.UIcodeSet );
		response.setCharacterEncoding( wid.UIcodeSet );
		response.setContentType("application/json");
		
		final boolean isMR = Boolean.parseBoolean( request.getParameter("isMR") );
		final String svnURL = request.getParameter("url");
		final String svnUSR = request.getParameter("usr");
		final String svnPWD = request.getParameter("pwd");
		final String relativePath = request.getParameter("relativePath");
		final String fileName = request.getParameter("fileName");
		
		ArrayList<L1S1> verSet = new ArrayList<L1S1>();
		
		try {
			verSet = wid.chkFileRevisionAndComment(isMR,svnURL,svnUSR,svnPWD,relativePath,fileName,wid.IS_STRICT );
		} catch (Exception e) {
			wid.errLog(e);
		}
		
		response.getWriter().write( new Gson().toJson(verSet) );
	}

}
